define(function(require){
	var $ = require("jquery");
	var justep = require("$UI/system/lib/justep");
    var check = require("$UI/communityOto/common/check");
	var Model = function(){
	    this.oldPwdOk = false;
	    this.newPwdOk = false;
	    this.confirePwdOk = false;
		this.callParent();
	};


    //保存密码
	Model.prototype.saveBtnClick = function(event){
	
	
	    if(this.oldPwdOk&&this.newPwdOk&&this.confirePwdOk){
	    	var oldPwd = this.comp("oldPwd").val();
			var newPwd = this.comp("newPwd").val();
			var userId = JSON.parse(localStorage.getItem("userInfo")).data[0].userId;
			//console.log(JSON.parse(localStorage.getItem("userInfo")).data[0])
		    var url = "http://www.xjzlhy.com:81/ex_community/a/api/community/modifyPwd?callback=?";
			$.getJSON(
					url,
					{
						id:userId,
						oldPassword:oldPwd,
						newPassword:newPwd
					},
					function(data){
						console.log(data);
						if(data.errNo == -1){
							justep.Util.hint(data.errMessage, {type:"danger"});
						}else{
							justep.Util.hint("修改成功", {type:"success"});
						}
					}
			);
	    }else{    
	    	justep.Util.hint("输入信息有错，请修改再保存", {type:"danger"});
	    }
		

	};

	Model.prototype.oldPwdBlur = function(event){
		if(!this.comp("oldPwd").val()){
			justep.Util.hint("请输入旧密码", {type:"danger"});
			this.oldPwdOk = false;
		}else{
			this.oldPwdOk = true;
		}
	};

	Model.prototype.newPwdBlur = function(event){
	
		if(!this.comp("newPwd").val()){
			justep.Util.hint("请输入新密码", {type:"danger"});
			this.newPwdOk = false;		
		}else if(!check.testPassword(this.comp("newPwd").val())){
			justep.Util.hint("请输入以字母开头的6-18个字母、数字或下划线", {type:"danger"});
			this.newPwdOk = false;		
		}else if(this.comp("newPwd").val()==this.comp("oldPwd").val()){
			justep.Util.hint("新密码不能和旧密码一样", {type:"danger"});
			this.newPwdOk = false;	
		}else {
			this.newPwdOk = true;
		}

	};

	Model.prototype.confirePwdBlur = function(event){
		if(!this.comp("confirePwd").val()){
			justep.Util.hint("请确认新密码", {type:"danger"});
			this.confirePwdOk = false;			
		}else if(this.comp("confirePwd").val()!=this.comp("newPwd").val()){			
			justep.Util.hint("两次输入密码不一致", {type:"danger"});	
			this.confirePwdOk = false;				
		}else{
			this.confirePwdOk = true;
		}
	};

	return Model;
});